class TreatmentGroupsController < ApplicationController
  before_action :set_treatment_group, only: [:show, :edit, :update, :destroy]

  # GET /treatment_groups
  # GET /treatment_groups.json
  def index
    @treatment_groups = TreatmentGroup.all
  end

  # GET /treatment_groups/1
  # GET /treatment_groups/1.json
  def show
  end

  # GET /treatment_groups/new
  def new
    @treatment_group = TreatmentGroup.new
  end

  # GET /treatment_groups/1/edit
  def edit
  end

  # POST /treatment_groups
  # POST /treatment_groups.json
  def create
    @treatment_group = TreatmentGroup.new(treatment_group_params)

    respond_to do |format|
      if @treatment_group.save
        format.html { redirect_to new_appointment_treatment_path(:appointment_id => params[:appointment_id]), notice: 'Kelompok Tindakan Baru telah Disimpan.' }
        format.json { render :show, status: :created, location: @treatment_group }
      else
        format.html { render :new }
        format.json { render json: @treatment_group.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /treatment_groups/1
  # PATCH/PUT /treatment_groups/1.json
  def update
    respond_to do |format|
      if @treatment_group.update(treatment_group_params)
        format.html { redirect_to @treatment_group, notice: 'Treatment group was successfully updated.' }
        format.json { render :show, status: :ok, location: @treatment_group }
      else
        format.html { render :edit }
        format.json { render json: @treatment_group.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /treatment_groups/1
  # DELETE /treatment_groups/1.json
  def destroy
    @treatment_group.destroy
    respond_to do |format|
      format.html { redirect_to treatment_groups_url, notice: 'Treatment group was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_treatment_group
      @treatment_group = TreatmentGroup.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def treatment_group_params
      params.require(:treatment_group).permit(:label, :created_at, :updated_at, :created_by, :updated_by)
    end
end
